//###############
//FILE : UserCommand.java
//WRITER : Daniel Lowengrub, daniel_i_l, 320687098
//EXERCISE : oop ex3 2011
//DESCRIPTION:
//See below
//###############
package oop.ex3.filemanager;

/**
 * Executes a command run by the user.
 * @author daniel
 */
public abstract class UserCommand {
    private static final int COMMAND_ARG = 0;
    protected static final String COMMAND_SPACER = " ";
    private String _commandName;

    /**
     * Construct a user command with a specific name that will be used to execute the
     * command.
     * @param commandName The command name.
     */
    public UserCommand (String commandName){
        _commandName = commandName;
    }

    /**
     * Checks if a certain command is of the right format to be executed by
     * theis command.
     * @param command The command to check.
     * @return True iff we can execute the command.
     */
    public boolean recognizeCommand(String command) {
        command = command.split(COMMAND_SPACER)[COMMAND_ARG];
        return command.equals(_commandName);
    }

    /**
     * Execute the given command.
     * @param command The command to execute.
     * @return True iff the execution was successfull.
     */
    public abstract boolean executeCommand(String command);
}
